﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;

using Wxits.Data;
using Wxits.Helper;


public partial class Admin_Logs : BasePage_Grid
{
    private string _id = string.Empty;


    private int _PageSize
	{
		set { ViewState["PageSize"] = value; }
		get
		{
			return Convert.ToInt32(ViewState["PageSize"]);
		}
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
            DataCheck.CheckAuthority();

            string strSQL = @"select * from Sys_Common_Class_Detail where ClassId = 2";
            DataTable dt = DBAccess.ExecuteDataTable(strSQL);
            ddlType.DataSource = dt;
            ddlType.DataTextField = "Name";
            ddlType.DataValueField = "value";
            ddlType.DataBind();
            ddlType.Items.Insert(0,new ListItem("全部",""));

            _PageSize = 10;
			ShowData(0, _PageSize);			
		}
	}

	private void ShowData(long PageIndex, long PageSize)
	{


        string strSQL = @"
					SELECT *	
						, (select Name from Sys_Common_Class_Detail where ClassId = 2 and value = a.LogsType) as LogTypeName
						,'UserTypeTxt' = 	
						CASE 
							WHEN UserType = 1 THEN N'前台会员' 
							ELSE N'后台管理员'
						END
					FROM Mall_Logs a
					WHERE 1 = 1 ";

        if (!string.IsNullOrEmpty(txtName.Text.Trim()))
            strSQL += " AND a.UserName like '%" + txtName.Text.Trim() + "%'";

        if (!string.IsNullOrEmpty(ddlType.SelectedValue))
            strSQL += " AND a.LogsType='"+ ddlType.SelectedValue + "'";

        strSQL += " ORDER BY a.cdate DESC";

        DataTable dt = DBAccess.ExecuteDataTable(strSQL);

        BindGrid(gvData, Navigator, PageIndex, PageSize, dt);
	}

	protected void Navigator_PageChanged(object sender, QHH.Web.UI.EventArg.NavigatorEventArgs e)
	{
		_PageSize = (int)e.PageSize;
		ShowData(e.NewPageIndex, _PageSize);
	}

	protected void Search_Click(object sender, EventArgs e)
	{
		ShowData(0, _PageSize);
	}
    protected string UrlEncodeStr(string Str)
    {
        return HttpUtility.UrlEncode(Str);
    }

    protected string CutStr(string Str, int Len)
    {
        return HelperString.Left(Len, Str);
    }

}
